package com.example.GeoCoder;
import java.util.List;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

public class MyListAdapter extends ArrayAdapter<PlaceObject> {
	private final Activity context;
	private final List<PlaceObject> list;

	public MyListAdapter(Activity context, List<PlaceObject> results) {
		super(context, R.layout.main, results);
		this.context = context;
		this.list = results;
	}

	static class ViewHolder {
		protected TextView venueTextView, addressTextView,urlTextView,optionNumberView;
		protected RatingBar ratingbarView;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = null;
		if (convertView == null) {
			LayoutInflater inflator = context.getLayoutInflater();
			rowView = inflator.inflate(R.layout.main, null);
			final ViewHolder viewHolder = new ViewHolder();
			viewHolder.optionNumberView = (TextView) rowView.findViewById(R.id.option);
			viewHolder.venueTextView = (TextView) rowView.findViewById(R.id.venuName);
			viewHolder.addressTextView = (TextView) rowView.findViewById(R.id.myaddress);
			viewHolder.urlTextView = (TextView) rowView.findViewById(R.id.url);
			viewHolder.ratingbarView = (RatingBar) rowView.findViewById(R.id.ratingbar);
			rowView.setTag(viewHolder);
		}else {
			rowView = convertView;
		}
		ViewHolder holder = (ViewHolder) rowView.getTag();
		holder.optionNumberView.setText("Option: "+(position+1));
		holder.venueTextView.setText(list.get(position).getVenueName());
		holder.addressTextView.setText(list.get(position).getAddress());
		holder.ratingbarView.setRating(Float.parseFloat(list.get(position).getRating()));
		return rowView;
	}
}